<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>登录</title>
    <!--jQuery-->
    <script type="text/javascript" src="/static/jQuery/jquery.js"></script>
</head>
<body>

<h2>登录</h2>
<form onsubmit="return false">
    <table>
        <tr>
            <td>登录名称：</td>
            <td>
                <input id="loginname" type="text" name="loginname" value="admin"/>
            </td>
        </tr>
        <tr>
            <td>登录密码：</td>
            <td>
                <input id="loginpass" type="password" name="loginpass" value="admin"/>
            </td>
        </tr>
    </table>
</form>
<table>
    <tr>
        <td colspan="2">
            <input type="submit" onclick="login()" value="注册"/>
            <input type="reset" value="重置"/>
        </td>
    </tr>
</table>

<script type="application/javascript">
// 登录逻辑
var login = function () {
    var loginname = $('#loginname').val();
    var loginpass = $('#loginpass').val();

    $.ajax({
        url:'/user/login',
        type: 'post',
	    contentType: 'application/json;charset=utf-8',
	    async: false,
	    data: JSON.stringify({loginname: loginname, loginpass: loginpass}),
	    dataType: 'json',
        success:function (json) {
            console.log(json)
            if (json.code == '200') {
                // 成功，跳转页面
                window.location.href = "/resume";
            } else {
                alert(json.msg);
            }
        },
        error:function () {
        }
    });
}
</script>

</body>
</html>
